<template>
  <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
    <el-menu-item index="1" @click="goRouter('/')">博客首页</el-menu-item>
    <el-submenu index="2">
      <template slot="title">热点资讯</template>
      <el-submenu index="2-1">
        <template slot="title">前端开发</template>
        <el-menu-item index="2-1-1">html</el-menu-item>
        <el-menu-item index="2-1-2">css</el-menu-item>
        <el-menu-item index="2-1-3">js</el-menu-item>
      </el-submenu>
      <el-submenu index="2-2">
        <template slot="title">后端开发</template>
        <el-menu-item index="2-2-1">Node.Js</el-menu-item>
        <el-menu-item index="2-2-2">Mongodb</el-menu-item>
        <el-menu-item index="2-2-3">Koa2</el-menu-item>
      </el-submenu>
    </el-submenu>
    <el-menu-item index="3" @click="goRouter('/message')">留言中心</el-menu-item>
    <el-menu-item index="4" @click="goRouter('/about')">关于本站 </el-menu-item>
    <el-menu-item index="5" @click="goRouter('/login')">
      <img class="headimg" src="../../assets/images/headimg.png" alt="" />
      &nbsp;&nbsp;
      <span>{{userState}}</span>
    </el-menu-item>
  </el-menu>
</template>

<script>
  export default {
    data() {
      return {
        activeIndex: '1',
        userState: "未登录"
      };
    },
    mounted() {
      let that = this
      that.userState = that.$store.state.userName
      switch (that.$route.path) {
        case '/articleList':
          that.activeIndex = '1'
          break;
        case '/about':
          that.activeIndex = '4'
          break;
        case '/message':
          that.activeIndex = '3'
          break;
        default:
          that.activeIndex = ""
      }
    },
    methods: {
      handleSelect(key) {
        console.log(key);
      },
      goRouter(path) {
        this.$router.push(path);
      }
    }
  };

</script>

<style lang="less" scoped>
  a {
    text-decoration: none;
  }

  .router-link-active {
    text-decoration: none;
  }

  .el-menu-demo {
    width: 100%;
    display: flex;
    justify-content: space-around;
    position: fixed;
    z-index: 99;
  }

  .headimg {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0px 1px 6px 0px orange;
  }

</style>
